package com.qdu.hyy.PopularityCount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class PopularityCountDriver {

    public static void main(String[] args) throws Exception {


        // 创建Hadoop配置对象
        Configuration conf = new Configuration();

        // 创建一个新的Job
        Job job = Job.getInstance(conf, "Movie Analysis");

        // 设置Job的Driver类
        job.setJarByClass(PopularityCountDriver.class);

        // 设置Mapper和Reducer类
        job.setMapperClass(PopularityCountMapper.class);
        job.setReducerClass(PopularityCountReducer.class);

        // 设置Mapper的输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(MovieCountRevenueWritable.class);

        // 设置Reducer的输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        // 设置输入和输出路径
        FileInputFormat.addInputPath(job, new Path("input/hyy/movies_complete.csv"));
        FileOutputFormat.setOutputPath(job, new Path("output/job4"));


        // 提交Job并等待完成
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}